﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AMS.DataAccess.Trademark.Filters;
using AMS.DataAccess.Filter;
using AMS.DataAccess;

public partial class RecvFile_ucSearchRecvFile : UCBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (txtSearchName.Text == "输入查询名称")
        {
            txtSearchName.Text = "";
        }
    }
    public string QueryName
    {
        get { return txtSearchName.Text; }
        set { txtSearchName.Text = value; }
    }

    public event EventHandler RecvFileFiltered;
    protected void OnRecvFileFiltered()
    {
        if (RecvFileFiltered != null)
        {
            RecvFileFiltered(this, EventArgs.Empty);
        }
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        OnRecvFileFiltered();
    }

    public RecvFileFilter GetRecvFileFilter()
    {
        RecvFileFilter filter = new RecvFileFilter();
        if (!string.IsNullOrEmpty(txtCaseIndex.Text))
        {
            filter.CaseIndex = new StringFilterField(txtCaseIndex.Text);
        }
        if (!string.IsNullOrEmpty(txtRFName.Text))
        {
            filter.RecvFileName = new StringFilterField(txtRFName.Text, StringOperations.Like);
        }
        if (chkShowMyRFOnly.Checked)
        {
            // TODO: apply owner id
            //filter.Owner = CallContext.UserID;
        }
        if (!chkOfficeRF.Checked || !chkCusInstructionRF.Checked || !chkCusOtherRF.Checked)
        {
            filter.RecvFileTypes = new List<string>();
            if (chkOfficeRF.Checked)
            {
                filter.RecvFileTypes.Add("O");
            }
            if (chkCusInstructionRF.Checked)
            {
                filter.RecvFileTypes.Add("C");
            }
            if (chkCusOtherRF.Checked)
            {
                // TODO: add for customer instructions
            }
        }

        DateTime dt = DateTime.Now;
        DateTime dtCompared = DateTime.MinValue;
        if (drpCreateDate.SelectedIndex > 0)
        {
            if (drpCreateDate.SelectedIndex == 1)
            {
                dtCompared = dt;
            }
            else if (drpCreateDate.SelectedIndex == 2)
            {
                dtCompared = dt.AddDays(-2);
            }
            else if (drpCreateDate.SelectedIndex == 3)
            {
                int daysToMonday = (int)dt.DayOfWeek - (int)DayOfWeek.Monday + 1;
                dtCompared = dt.AddDays(0 - daysToMonday);
            }
            else
            {
                dtCompared = dt.AddDays(0 - dt.Day + 1);
            }

            filter.CreateDate = new DateTimeFilterField(dtCompared, DateTimeType.Date, SqlOperations.LargerThanOrEquals);
        }

        return filter;
    }
}
